/**
	装载下拉框的角色列表
 */
var searchForm = $(document.forms.searchForm);
var orderId = $(document.forms.searchForm.orderStatus);
$.get(
	"admin/mallorder.let?action=orderStatue",
	function(data){
		for(let orderStatue of data) {
			orderId.append(`<option value="${orderStatue.orderStatus}">${orderStatue.orderStatus}</option>`);
		}
	},"json"
);



//保存查询条件
var searchParams = new URLSearchParams();
searchForm.on("submit",function(){
	searchParams = sys.form.param(searchForm[0]);
	datagrid.bootstrapTable("refresh",{pageNumber:1});
	return false;
});


var datagrid = $("#datagrid").bootstrapTable({
	url: "admin/mallorder.let?action=page",
	dataField: "list",//rows
	totalField: "total",
	queryParamsType: "",//limit
	pagination: true,
	sidePagination: "server",//client
	queryParams:function(params) { 
	  for(let name of searchParams.keys()){//添加搜索条件
		  console.info(name+"="+searchParams.get(name));
		  params[name]=searchParams.get(name);
	  }
	  console.info(params);
	  return params 
    }
});



var indexFormatter = function(value, row, index, fieldName) {
	return index + 1;
}




/**
 * 格式化表格操作菜单
 */
var optionFormatter = function(value, row, index) {
	return `<div class="dropdown">
  <button class="btn btn-outline-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">
    操作
  </button>
  <div class="dropdown-menu dropdown-menu-right">
     <a class="dropdown-item  _deliver" href="admin/mallorder.let?action=deliver&orderDetailId=${value}" >发货</a>
  </div>
</div>`;
}






var ss = ["待付款","待发货","待收货"];
/**
 * 格式化表格操作菜单
 */
var optionFormatter = function(value, row, index) {
	return `<div class="dropdown">
  <button class="btn btn-outline-primary btn-block dropdown-toggle" type="button" data-toggle="dropdown">
    操作
  </button>
  <div class="dropdown-menu dropdown-menu-right">
     <a class="dropdown-item  _deliver" data-index="${index}" href="javascript:void(0);" >发货</a>
  </div>
</div>`;
}

datagrid.on("click", "._deliver", function() {//发货
	let obj = $(this);
	let index = obj.data("index");//data-index
	let row = datagrid.bootstrapTable("getData")[index];
	sys.confirm(`您确定发货[${row.orderId}]号订单啊吗？`, function(r) {
		if (r) {
			$.post(
				"admin/mallorder.let?action=deliver",
				{ "orderId": row.orderId },
				function(data) {
					if (data.code == 200) {
						sys.toastr.success(`订单[${row.orderId}]发货成功`);
						datagrid.bootstrapTable("refresh");
					} else {
						sys.toastr.error(data.message);
					}
				}, "json"
			);
		}
	});
});

var ss = ["待付款","待发货","待发货"];

var statusFormatter = function(value) {
	return `<b>${ss[value]}</b>`;
}

